
def sort_word(word):
    sig = ''.join(sorted(word))
    return (sig, word)

def cmp(tup1, tup2):
    return strcmp(tup1[0], tup2[2])

def hash_wordlist(wordlist):
    return [sort_word(word) for word in wordlist] 

def sort_wordlist(wordlist):
    hashlist = hash_wordlist(wordlist)
    sortedlist = sorted(hashlist, key=lambda x:x[0])
    return sortedlist

def same_hash_word(sortedlist):
    i = 0
    signed = ''
    for word in sortedlist: 
        if signed == word[0]:
            print word[1],
            continue
        else:
            signed = word[0]
            if  i != 0 :
                print 
            print  word[1],
        i += 1

if __name__ == '__main__':
    wordlist = ['spot', 'beautiful', 'tops', 'post', 'technology', 'technoloyg', 'spots', 'tpos']
    sortedlist = sort_wordlist(wordlist)
    same_hash_word(sortedlist)
